from RSA import RSA
from utils import textToHex, hexToText


if __name__ == "__main__":


    '''
----------生成公钥对和私钥对---------------------------
    '''

    pk, sk = RSA().generateKeys(size=2048)
    print("公钥: ",(hex(pk[0]), hex(pk[1])),end="\n\n")
    print("私钥: ",(hex(sk[0]), hex(sk[1])),end="\n\n")



    '''
----------加密过程示例---------------------------
    '''

    # pt = "mount"
    pt = "2002 A.M. TURING AWARD. RSA, an acronym for Rivest, Shamir and Adleman, uses algorithmic number theory to provide an efficient realization of a public-key cryptosystem, a concept first envisioned theoretically by Whitfield Diffie, Martin Hellman and Ralph Merkle. RSA is now the most widely used encryption method, with applications throughout the Internet to secure on-line transactions. It has also inspired breakthrough work in both theoretical computer science and mathematics."
    print("明文文本:\n", pt)
    print("明文hex:\n", textToHex(pt))
    ct = RSA().encrypt(pt=eval(textToHex(pt)), pk=pk)
    print("加密结果:\n",hex(ct))



    '''
----------解密过程示例---------------------------
    '''
    res = RSA().decrypt(ct=ct, sk=sk)
    print("解密结果:\n",hex(res))
    print("解密文本:\n",hexToText(hex(res)))
